import { Controller, Post, Body } from "@nestjs/common";
import { UploadHistoryService } from "../service/upload.history.service";
import { UploadHistoryQueryDto, UploadHistoryRemoveDto } from "src/dto/upload";
import { ApiRes, RequsetUser, UsePermGuard, definePermission } from "src/decorator";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { UploadHistoryEntity } from "src/entity";
import { Perm as FilePerm } from "src/file/file.controller";

const Perm = definePermission("user:upload_history", {
    query: {
        name: "查询",
        code: "query",
        description: "用户上传记录查询权限",
    },
    remove: {
        name: "移除",
        code: "remove",
        description: "用户上传记录移除权限",
    },
} as const);

@ApiTags("User - 模块", "Upload - 模块")
@Controller("user")
export class UploadHistoryController {
    constructor(private readonly uploadHistoryService: UploadHistoryService) {}

    @ApiOperation({ summary: "上传记录列表" })
    @ApiRes({ type: UploadHistoryEntity, pagination: true })
    @UsePermGuard(Perm.QUERY, FilePerm.UPLOAD)
    @Post("query_upload_history")
    queryUploadHistory(@RequsetUser("id") id: number, @Body() upload: UploadHistoryQueryDto) {
        return this.uploadHistoryService.query(id, upload);
    }

    @ApiOperation({ summary: "移除上传记录" })
    @UsePermGuard(Perm.REMOVE)
    @Post("remove_upload_history")
    removeUploadHistory(@RequsetUser("id") id: number, @Body() upload: UploadHistoryRemoveDto) {
        return this.uploadHistoryService.remove(id, upload);
    }
}
